/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.camachosanchez.gui;

import com.camachosanchez.bean.Almacenes;
import com.camachosanchez.bean.EstadosMedicion;
import com.camachosanchez.bean.EstadosNeumaticos;
import com.camachosanchez.bean.MarcasNeumatico;
import com.camachosanchez.bean.ModelosBandaNeumatico;
import com.camachosanchez.bean.Neumaticos;
import com.camachosanchez.bean.TipoPiso;
import com.camachosanchez.controler.jpa.AlmacenesJpaController;
import com.camachosanchez.controler.jpa.EstadosMedicionJpaController;
import com.camachosanchez.controler.jpa.EstadosNeumaticosJpaController;
import com.camachosanchez.controler.jpa.MarcasNeumaticoJpaController;
import com.camachosanchez.controler.jpa.ModelosBandaNeumaticoJpaController;
import com.camachosanchez.controler.jpa.TipoPisoJpaController;
import com.camachosanchez.reportes.ReporteNeumaticosXCategoria;
import com.camachosanchez.util.Constantes;
import com.camachosanchez.util.GUIUtil;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.swing.DefaultComboBoxModel;
/**
 *
 * @author ZULLY
 */
public class DialogoReporteNeumaticosXCategoria extends javax.swing.JDialog {

    /**
     * Creates new form DialogoReporteNeumaticosXCategoria
     */
    public DialogoReporteNeumaticosXCategoria(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        GUIUtil.addEscapeKey(this);
        cargarCombos();
        dateDesde.setDate(new Date());
        dateHasta.setDate(new Date());
//        Dimension size = new Dimension(560, 330);
//        setSize(size);
//        setPreferredSize(size);
//        setMinimumSize(size);
//        setMaximumSize(size);
        setResizable(false);
        pack();
        setLocationRelativeTo(null);
        cmbMarca.requestFocusInWindow();
//        
    }

    private void cargarCombos(){
        MarcasNeumaticoJpaController dao_marcas = new MarcasNeumaticoJpaController(null);
        AlmacenesJpaController dao_almacenes = new AlmacenesJpaController(null);
        TipoPisoJpaController dao_tipos_piso = new TipoPisoJpaController(null);
        EstadosNeumaticosJpaController dao_estados = new EstadosNeumaticosJpaController(null);
        ModelosBandaNeumaticoJpaController dao_bandas = new ModelosBandaNeumaticoJpaController(null);
        EstadosMedicionJpaController dao_estadosMedicion = new EstadosMedicionJpaController(null);
        List<MarcasNeumatico> marcas = dao_marcas.findMarcasNeumaticoEntities();
        List<Almacenes> almacenes = dao_almacenes.findAlmacenesEntities();
        List<TipoPiso> tipos_piso = dao_tipos_piso.findTipoPisoEntities();
        List<EstadosNeumaticos> estados = dao_estados.findEstadosNeumaticosEntities();
        List<ModelosBandaNeumatico> bandas = dao_bandas.findModelosBandaNeumaticoEntities();
        List<EstadosMedicion> estadosMedicion = dao_estadosMedicion.findEstadosMedicionEntities();
        marcas.add(0, null);
        almacenes.add(0, null);
        tipos_piso.add(0, null);
        estados.add(0, null);
        bandas.add(0, null);
        estadosMedicion.add(0, null);
        cmbMarca.setModel(new DefaultComboBoxModel(marcas.toArray()));
        cmbAlmacen.setModel(new DefaultComboBoxModel(almacenes.toArray()));
        cmbTipoPiso.setModel(new DefaultComboBoxModel(tipos_piso.toArray()));
        cmbMedida.setModel(new DefaultComboBoxModel(bandas.toArray()));
        cmbEstado.setModel(new DefaultComboBoxModel(estados.toArray()));
        cmbEstadoMedicion.setModel(new DefaultComboBoxModel(estadosMedicion.toArray()));
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar1 = new javax.swing.JToolBar();
        jPanel5 = new javax.swing.JPanel();
        btnDespinches = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        checkStock = new javax.swing.JCheckBox();
        checkMontado = new javax.swing.JCheckBox();
        checkReencauche = new javax.swing.JCheckBox();
        checkCementerio = new javax.swing.JCheckBox();
        checkReparacion = new javax.swing.JCheckBox();
        checkReclamo = new javax.swing.JCheckBox();
        checkBodega = new javax.swing.JCheckBox();
        checkParaReencauche = new javax.swing.JCheckBox();
        jPanel2 = new javax.swing.JPanel();
        checkFechaCompra = new javax.swing.JCheckBox();
        jPanel4 = new javax.swing.JPanel();
        jLabel16 = new javax.swing.JLabel();
        cmbMarca = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        cmbAlmacen = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        cmbTipoPiso = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        cmbMedida = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        cmbEstado = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        cmbEstadoMedicion = new javax.swing.JComboBox();
        jPanel6 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        dateDesde = new com.toedter.calendar.JDateChooser();
        jLabel3 = new javax.swing.JLabel();
        dateHasta = new com.toedter.calendar.JDateChooser();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle(".:: Neumáticos por Ubicación ::.");
        setMinimumSize(new java.awt.Dimension(407, 54));

        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);
        jToolBar1.setMinimumSize(new java.awt.Dimension(73, 30));

        jPanel5.setBackground(new java.awt.Color(255, 255, 255));
        jPanel5.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel5.setPreferredSize(new java.awt.Dimension(69, 28));
        jPanel5.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 2, 2));

        btnDespinches.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/camachosanchez/recursos/pdf.png"))); // NOI18N
        btnDespinches.setText("Imprimir");
        btnDespinches.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        btnDespinches.setContentAreaFilled(false);
        btnDespinches.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDespinchesActionPerformed(evt);
            }
        });
        jPanel5.add(btnDespinches);

        jToolBar1.add(jPanel5);

        getContentPane().add(jToolBar1, java.awt.BorderLayout.PAGE_START);

        jPanel3.setBackground(new java.awt.Color(231, 239, 247));

        jPanel1.setBackground(new java.awt.Color(231, 239, 247));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Categorías"));
        jPanel1.setLayout(new java.awt.GridLayout(3, 3));

        checkStock.setBackground(new java.awt.Color(231, 239, 247));
        checkStock.setText("En Stock");
        jPanel1.add(checkStock);

        checkMontado.setBackground(new java.awt.Color(231, 239, 247));
        checkMontado.setText("Montado");
        jPanel1.add(checkMontado);

        checkReencauche.setBackground(new java.awt.Color(231, 239, 247));
        checkReencauche.setText("Enviado a Reencauche");
        jPanel1.add(checkReencauche);

        checkCementerio.setBackground(new java.awt.Color(231, 239, 247));
        checkCementerio.setText("Enviado a Cementerio");
        jPanel1.add(checkCementerio);

        checkReparacion.setBackground(new java.awt.Color(231, 239, 247));
        checkReparacion.setText("Enviado a Reparación");
        jPanel1.add(checkReparacion);

        checkReclamo.setBackground(new java.awt.Color(231, 239, 247));
        checkReclamo.setText("En Reclamo");
        jPanel1.add(checkReclamo);

        checkBodega.setBackground(new java.awt.Color(231, 239, 247));
        checkBodega.setText("En Bodega Provisional");
        jPanel1.add(checkBodega);

        checkParaReencauche.setBackground(new java.awt.Color(231, 239, 247));
        checkParaReencauche.setText("Para ser Enviado a Reencauche");
        jPanel1.add(checkParaReencauche);

        jPanel2.setBackground(new java.awt.Color(231, 239, 247));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Filtro"));

        checkFechaCompra.setBackground(new java.awt.Color(231, 239, 247));
        checkFechaCompra.setText("Fecha de Compra:");
        checkFechaCompra.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        checkFechaCompra.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        checkFechaCompra.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkFechaCompraActionPerformed(evt);
            }
        });

        jPanel4.setOpaque(false);
        jPanel4.setLayout(new java.awt.GridLayout(3, 4, 3, 3));

        jLabel16.setText("Marca:");
        jPanel4.add(jLabel16);

        cmbMarca.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jPanel4.add(cmbMarca);

        jLabel6.setText("Almacén:");
        jPanel4.add(jLabel6);

        cmbAlmacen.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jPanel4.add(cmbAlmacen);

        jLabel8.setText("Tipo de Piso:");
        jPanel4.add(jLabel8);

        cmbTipoPiso.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jPanel4.add(cmbTipoPiso);

        jLabel9.setText("Medida:");
        jPanel4.add(jLabel9);

        cmbMedida.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jPanel4.add(cmbMedida);

        jLabel4.setText("Estado:");
        jPanel4.add(jLabel4);

        cmbEstado.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jPanel4.add(cmbEstado);

        jLabel5.setText("Estado en medición:");
        jPanel4.add(jLabel5);

        cmbEstadoMedicion.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jPanel4.add(cmbEstadoMedicion);

        jPanel6.setOpaque(false);
        jPanel6.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 0));

        jLabel2.setText("Desde:");
        jLabel2.setPreferredSize(new java.awt.Dimension(40, 20));
        jPanel6.add(jLabel2);

        dateDesde.setDateFormatString("dd/MM/yyyy");
        dateDesde.setEnabled(false);
        dateDesde.setMaxSelectableDate(new Date());
        dateDesde.setPreferredSize(new java.awt.Dimension(120, 20));
        dateDesde.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                dateDesdePropertyChange(evt);
            }
        });
        jPanel6.add(dateDesde);

        jLabel3.setText("Hasta:");
        jLabel3.setMaximumSize(new java.awt.Dimension(38, 14));
        jLabel3.setMinimumSize(new java.awt.Dimension(38, 14));
        jLabel3.setPreferredSize(new java.awt.Dimension(38, 14));
        jPanel6.add(jLabel3);

        dateHasta.setDateFormatString("dd/MM/yyyy");
        dateHasta.setEnabled(false);
        dateHasta.setMaxSelectableDate(new Date());
        dateHasta.setPreferredSize(new java.awt.Dimension(120, 20));
        jPanel6.add(dateHasta);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(checkFechaCompra, javax.swing.GroupLayout.DEFAULT_SIZE, 507, Short.MAX_VALUE)
                        .addGap(14, 14, 14))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, 511, Short.MAX_VALUE)
                            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, 511, Short.MAX_VALUE))
                        .addContainerGap())))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(checkFechaCompra, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel3, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnDespinchesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDespinchesActionPerformed
        // TODO add your handling code here:
        final DialogoCargando dlg = new DialogoCargando(Principal.getInstance(), true);
        Thread hilo = new Thread() {

            @Override
            public void run() {
                Neumaticos neumatico = new Neumaticos();
                MarcasNeumatico marca = (MarcasNeumatico) cmbMarca.getSelectedItem();
                Almacenes almacen = (Almacenes) cmbAlmacen.getSelectedItem();
                TipoPiso tipoPiso = (TipoPiso) cmbTipoPiso.getSelectedItem();
                EstadosNeumaticos estado = (EstadosNeumaticos) cmbEstado.getSelectedItem();
                ModelosBandaNeumatico modeloBanda = (ModelosBandaNeumatico) cmbMedida.getSelectedItem();
                EstadosMedicion estadoM = (EstadosMedicion) cmbEstadoMedicion.getSelectedItem();
                neumatico.setIdMarca(marca);
                neumatico.setIdAlmacen(almacen);
                neumatico.setTipoPiso(tipoPiso);
                neumatico.setIdEstado(estado);
                neumatico.setIdModelo(modeloBanda);
                neumatico.setIdEstadoMedicion(estadoM);
                Date fechaDesde = null, fechaHasta = null;
                if(checkFechaCompra.isSelected()){
                    fechaDesde = dateDesde.getDate();
                    fechaHasta = dateHasta.getDate();
                }
                List<Integer> categorias = new ArrayList<Integer>();
                if(checkStock.isSelected()){
                    categorias.add(Constantes.CATEGORIA_STOCK);
                }
                if(checkMontado.isSelected()){
                    categorias.add(Constantes.CATEGORIA_MONTADO);
                }
                if(checkReencauche.isSelected()){
                    categorias.add(Constantes.CATEGORIA_REENCAUCHE);
                }
                if(checkCementerio.isSelected()){
                    categorias.add(Constantes.CATEGORIA_CEMENTERIO);
                }
                if(checkReparacion.isSelected()){
                    categorias.add(Constantes.CATEGORIA_REPARACION);
                }
                if(checkReclamo.isSelected()){
                    categorias.add(Constantes.CATEGORIA_RECLAMO);
                }
                if(checkBodega.isSelected()){
                    categorias.add(Constantes.CATEGORIA_BODEGA);
                }
                if(checkParaReencauche.isSelected()){
                    categorias.add(Constantes.CATEGORIA_PARA_REENCAUCHE);
                }
                ReporteNeumaticosXCategoria reporte = new ReporteNeumaticosXCategoria();
                reporte.generarReporte(neumatico, categorias, fechaDesde, fechaHasta);
                dlg.dispose();
            }
        };
        hilo.start();
        dlg.setVisible(true);
    }//GEN-LAST:event_btnDespinchesActionPerformed

    private void checkFechaCompraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkFechaCompraActionPerformed
        // TODO add your handling code here:
        dateDesde.setEnabled(checkFechaCompra.isSelected());
        dateHasta.setEnabled(checkFechaCompra.isSelected());
    }//GEN-LAST:event_checkFechaCompraActionPerformed

    private void dateDesdePropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_dateDesdePropertyChange
        // TODO add your handling code here:
        if (evt.getPropertyName().compareTo("date") == 0) {
            dateHasta.setMinSelectableDate(dateDesde.getDate());
        }
    }//GEN-LAST:event_dateDesdePropertyChange

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnDespinches;
    private javax.swing.JCheckBox checkBodega;
    private javax.swing.JCheckBox checkCementerio;
    private javax.swing.JCheckBox checkFechaCompra;
    private javax.swing.JCheckBox checkMontado;
    private javax.swing.JCheckBox checkParaReencauche;
    private javax.swing.JCheckBox checkReclamo;
    private javax.swing.JCheckBox checkReencauche;
    private javax.swing.JCheckBox checkReparacion;
    private javax.swing.JCheckBox checkStock;
    private javax.swing.JComboBox cmbAlmacen;
    private javax.swing.JComboBox cmbEstado;
    private javax.swing.JComboBox cmbEstadoMedicion;
    private javax.swing.JComboBox cmbMarca;
    private javax.swing.JComboBox cmbMedida;
    private javax.swing.JComboBox cmbTipoPiso;
    private com.toedter.calendar.JDateChooser dateDesde;
    private com.toedter.calendar.JDateChooser dateHasta;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JToolBar jToolBar1;
    // End of variables declaration//GEN-END:variables
}
